package com.yaoyanshe.trialfield.common.base;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.yaoyanshe.trialfield.common.R;


/**
 * <p>description:</p>
 * <p>created on: 2020/5/13 14:42</p>
 *
 * @author tck
 * @version v1.0.3
 */
public abstract class BaseActivity extends AppCompatActivity {

    public Context mContext;

    public String TAG = getClass().getSimpleName();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        mContext = this;
        initData();
        initView();
        setViewData();
        setListener();
    }

    /**
     * 返回布局文件
     *
     * @return 布局文件Id
     */
    protected abstract int getLayoutId();

    public void initData() {

    }

    public void initView() {

    }

    public void setViewData() {

    }

    public void setListener() {

    }

    /**
     * 关闭软键盘
     */
    protected void toggleKeyboard(View view) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null && view != null) {
            imm.toggleSoftInputFromWindow(view.getWindowToken(), 0, 0);
        }
    }

    protected void showSoftInput(View view) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null && view != null) {
            imm.showSoftInput(view, 0);
        }
    }

    /**
     * 软键盘开关
     */
    protected void closeKeyboard(View view) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null && view != null) {
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    }

    protected void closeActivity() {
        finish();
        overridePendingTransition(R.anim.left_in, R.anim.right_out);
    }

    protected void openActivityAnimation() {
        overridePendingTransition(R.anim.right_in, R.anim.left_out);
    }
}
